package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2023-11-13
 * Time: 13:51
 */


/*public interface IShape {

    void darw();
    // 编译失败：因为接口中的方式默认为抽象方法
    // Error:(5, 23) java: 接口抽象方法不能带有主体
    public static void draw1() {
        System.out.println("画图形!");
    }
}*/
/*
public interface IShape {
    void openDevice();
    // 编译失败：因为接口中的方式默认为抽象方法
// Error:(5, 23) java: 接口抽象方法不能带有主体
    void closeDevice(){
        System.out.println("关闭USB设备");
    }
*/

/*// USB接口
public interface USB {
    void openDevice();
    void closeDevice();
}
// 鼠标类，实现USB接口
public class Mouse implements USB {
    @Override
    public void openDevice() {
        System.out.println("打开鼠标");
    }
    @Override
    public void closeDevice() {
        System.out.println("关闭鼠标");
    }
    public void click(){
        System.out.println("鼠标点击");
    }
}
// 键盘类，实现USB接口
public class KeyBoard implements USB {
    @Override
    public void openDevice() {
        System.out.println("打开键盘");
    }
    @Override
    public void closeDevice() {
        System.out.println("关闭键盘");
    }
    public void inPut(){
        System.out.println("键盘输入");
    }
}
// 笔记本类：使用USB设备
public class Computer {
    public void powerOn(){
        System.out.println("打开笔记本电脑");
    }
    public void powerOff(){
        System.out.println("关闭笔记本电脑");
    }
    public void useDevice(USB usb){
        usb.openDevice();
        if(usb instanceof Mouse){
            Mouse mouse = (Mouse)usb;
            mouse.click();
        }else if(usb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard)usb;
            keyBoard.inPut();
        }
        usb.closeDevice();
    }
}
// 测试类：
public class TestUSB {
    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.powerOn();
// 使用鼠标设备
        computer.useDevice(new Mouse());
// 使用键盘设备
        computer.useDevice(new KeyBoard());
        computer.powerOff();
    }
}*/



/*
        public class Test {

}
*/

abstract class Shape {
    public abstract void draw();//抽象方法
}

class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("🟢");
    }
}

class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("🖼️");
    }
}
public class Test {

    public static void drawMap(Shape shape) {
        shape.draw();
    }
    public static void main(String[] args) {
        Shape shape = new Cycle();
        Shape shape1 = new Rect();
        drawMap(shape);
        drawMap(shape1);
    }
}

